package astrologer.validator;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author hungnp
 */
@ManagedBean
@SessionScoped
public class Search {
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public ResultSet getRs() {
        return rs;
    }

    public void setRs(ResultSet rs) {
        this.rs = rs;
    }
    int row=0;
    ResultSet rs = null;
    Connection con=null;
    PreparedStatement pr=null;

    /** Creates a new instance of Search */
    public Search() {
    }
    
    public String search() {
        String url = "jdbc:sqlserver://localhost:1433;databaseName=MySweetHome;user=sa;password=123456";
        
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(url);
            System.out.println("Da ket noi co so du lieu");

            pr = con.prepareStatement("Select * from Account where Fullname like '%"+name+"%'", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = pr.executeQuery();
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }
        return "result";
    }

}
